import QtQuick 1.1

Rectangle {
    id: progressBar
    property real minValue: 0
    property real maxValue: 100
    property real value: 0
    property string color: "blue"
    property string colorText: "grey"
    property int timeAnim: 1400

    clip: true
    border.color: "gray"
    radius: 10
    gradient: Gradient {
        GradientStop { position: 0; color: theme.inverted === false ? "#505050" : "gray"  }
        GradientStop { position: 0.15; color: "transparent" }
        GradientStop { position: 0.85; color: "transparent" }
        GradientStop { position: 1; color: theme.inverted === false ? "#505050" : "gray" }
    }

    Rectangle {
        id: valFill
        anchors.verticalCenter: parent.verticalCenter
        anchors.left: parent.left
        anchors.leftMargin: 1
        width: ( (parent.maxValue - parent.minValue) !== 0 ) ? parent.width*(parent.value / (parent.maxValue - parent.minValue) ) - 2 : 0
        Behavior on width { SpringAnimation { spring: 1.4; damping: 0.1 } }
        height: parent.height*0.88
        radius: 10
        gradient: Gradient {
            GradientStop { position: 0; color:  theme.inverted === false ? "#505050" : "gray" }
            GradientStop { position: 0.35; color: progressBar.color }
            GradientStop { position: 0.65; color: progressBar.color }
            GradientStop { position: 1; color: theme.inverted === false ? "#505050" : "gray" }
        }
    }

    Text {
        id: valuePr
        text: ( (parent.maxValue - parent.minValue) !== 0 ) ? Math.round(parent.value / (parent.maxValue - parent.minValue)*100) + " %" : "0 %"
        anchors.horizontalCenter: parent.horizontalCenter
        anchors.verticalCenter: parent.verticalCenter
        font.pixelSize: parent.height*0.6
        color: colorText
    }

}
